#! /bin/bash

echo "**********************************************"
echo "Collecting c++, c source and header files ..."
time find `pwd` -path `pwd`/out -prune -o  \( -name "*.cpp" -o -name "*.cc" -o -name "*.c" -o -name "*.h" -o -name "*.hpp" -o -name "*.java" \) -print > cscope.files

echo "Got `wc -l cscope.files | awk '{print $1}'` source code files for cscope to analysis, building cscope index ..."
time cscope -Rbq 2> /dev/null

echo "Building ctags index ..."
time ctags -L cscope.files
#rm -f cscope.files

echo -n "Need to add tags/cscope.out to ~/.vimrc? [Yes|No]:"
read choice

if [  -n "$choice" ] &&  [  `expr "$choice" : "[Yy]"` -ne 0 ] 
then
    will_add=""

    echo "" >> ~/.vimrc
    echo "\" add ctags & cscope indexes" >> ~/.vimrc
    echo "set tags=`pwd`/tags" >> ~/.vimrc
    echo "cs add `pwd`/cscope.out" >> ~/.vimrc
else
    will_add="**NOT**"
fi

echo "Tags && cscope index files $will_add added to vimrc"

echo "Done"
echo "**********************************************"
exit
